<?php

namespace App\Http\Controllers\User;

use App\Model\User;
use App\Http\Controller;

class UserController extends Controller
{

    public function store($request)
    {
        $params = $request->getParams();
        // $user_id = $this->container->jwt->sub->id;

        $user = new User();

        if (isset($params['username']) && isset($params['password'])) {

            $options = [
                'cost' => 12,
            ];

            $user->username = $params['username'];
            $user->password = password_hash($params['password'], PASSWORD_DEFAULT, $options);

            try {
                $user->save();
            } catch(\Exception $e) {
                parent::log('QUERY', [$e->getMessage()]);
            }

        } else {
            return '参数缺失';
        }
    }

    public function test($request)
    {
        $user = new User();

        $username = 'zhurongpeng';
        $password = '123456';

        $options = [
            'cost' => 12,
        ];

        $user->username = $username;
        $user->password = password_hash($password, PASSWORD_DEFAULT, $options);

        var_dump('test');exit;

        try {
            $user->save();
        } catch(\Exception $e) {
            var_dump($e->getMessage());
        }
    }

    public function update()
    {

    }
}
